       IDENTIFICATION DIVISION.
      *  -------------------------------------------------------------
       PROGRAM-ID. RUTCLI.
      * -------------------------------------------------------------
       ENVIRONMENT DIVISION.
      *--------------------------------------------------------------
       CONFIGURATION SECTION.

       SPECIAL-NAMES.
           DECIMAL-POINT IS COMMA.

       INPUT-OUTPUT SECTION.

       FILE-CONTROL.
           SELECT CLI-IDX ASSIGN TO
                          "C:\ARCHIVOS\ENTRADAS\CLIIDX.TXT"
                                   ORGANIZATION IS INDEXED
                                   ACCESS MODE IS RANDOM
                                   RECORD KEY IS CIDX-COD
                                   ALTERNATE KEY IS CIDX-CUIT
                                   FILE STATUS IS FS-CLI.

      *--------------------------------------------------------------
       DATA DIVISION.
      *-------------------------------------------------------------
       FILE SECTION.
       FD  CLI-IDX.
       01  R-CLI-IDX.
           03  CIDX-COD.
               05  CIDX-COD-CLI                   PIC 9(11).
           03  CIDX-CUIT.
               05  CIDX-CUIT-CLI                  PIC 9(11).
           03  CIDX-RAZON-SOCIAL                  PIC X(30).
           03  CIDX-DOMICILIO                     PIC X(30).
           03  CIDX-PORC-DESC                     PIC 9(2)V99.

       WORKING-STORAGE SECTION.
       01  FS-CLI                                 PIC 99.
       01  ERRORES-FS-CLI.
           03  ERR-OPEN                        PIC X(21)
               VALUE "ERROR OPEN CLIENTES: ".
           03  ERR-23                          PIC X(20)
               VALUE "REGISTRO NO EXISTE: ".
           03  ERR-READ                        PIC X(21)
               VALUE "ERROR READ CLIENTES: ".
           03  ERR-CLOSE                       PIC X(22)
               VALUE "ERROR CLOSE CLIENTES: ".

       LINKAGE SECTION.
       01  LS-TIPO-CLAVE                          PIC X(1).
       01  LS-CLI-CLAVE                           PIC 9(11).
       01  LS-RAZON-SOCIAL                        PIC X(30).
       01  LS-DOMICILIO                           PIC X(30).
       01  LS-PORC-DESC                           PIC 9(2)V99.


      *---------------------------------------------------------------
       PROCEDURE DIVISION USING
           LS-TIPO-CLAVE LS-CLI-CLAVE LS-RAZON-SOCIAL
           LS-DOMICILIO LS-PORC-DESC.

       MAIN-SUBRUT.
           PERFORM CONFIRMAR THRU F-CONFIRMAR.
           PERFORM ABRIR THRU F-ABRIR.
           PERFORM CERRAR THRU F-CERRAR.
           PERFORM BUSCAR THRU F-BUSCAR.
           PERFORM FIN THRU F-FIN.

       CONFIRMAR.
      *     DISPLAY 'CONFIRMA'.
           IF (LS-TIPO-CLAVE NOT EQUAL 'C'
             AND LS-TIPO-CLAVE NOT EQUAL 'O'
             AND LS-TIPO-CLAVE NOT EQUAL 'A'
             AND LS-TIPO-CLAVE NOT EQUAL 'P')
               THEN PERFORM ERROR-OPC-INV THRU F-ERROR-OPC-INV.
       F-CONFIRMAR. EXIT.

       ABRIR.
           IF LS-TIPO-CLAVE EQUAL 'O'
      *       DISPLAY 'ABRIR'
               OPEN I-O CLI-IDX
               IF FS-CLI NOT = 0
                   DISPLAY ERR-OPEN FS-CLI
                   PERFORM FIN THRU F-FIN
               END-IF
           END-IF.
       F-ABRIR. EXIT.

       CERRAR.
           IF LS-TIPO-CLAVE EQUAL 'C'
      *       DISPLAY 'CERRAR'
               CLOSE CLI-IDX
               IF FS-CLI NOT = 0
                   DISPLAY ERR-CLOSE FS-CLI
                   PERFORM FIN THRU F-FIN
               END-IF
           END-IF.
       F-CERRAR. EXIT.

       BUSCAR.
           IF LS-TIPO-CLAVE EQUAL 'A' OR
             LS-TIPO-CLAVE EQUAL 'P'
           THEN
      *         DISPLAY 'BUSCAR'
               PERFORM PORCLAVE THRU F-PORCLAVE
           END-IF.
       F-BUSCAR. EXIT.

       PORCLAVE.
      *     DISPLAY 'BUSCA POR CLAVE'.
           IF LS-TIPO-CLAVE EQUAL 'A'
             THEN PERFORM PORCUIT THRU F-PORCUIT
           ELSE
             PERFORM PORCODIGO THRU F-PORCODIGO.
       F-PORCLAVE. EXIT.

       PORCUIT.
      *     DISPLAY 'BUSCA EL REGISTRO POR CUIT'.
           MOVE LS-CLI-CLAVE TO CIDX-CUIT-CLI.
           READ CLI-IDX
               KEY IS CIDX-CUIT
           END-READ.
      *----
           IF FS-CLI NOT = 0
               IF FS-CLI = 23
                   DISPLAY ERR-23 FS-CLI
               ELSE
                   DISPLAY ERR-READ FS-CLI
                   PERFORM FIN THRU F-FIN
               END-IF
           ELSE
               PERFORM COPIAR THRU F-COPIAR
           END-IF.
       F-PORCUIT. EXIT.

       PORCODIGO.
      *     DISPLAY 'BUSCA EL REGISTRO POR CODIGO'.
           MOVE LS-CLI-CLAVE TO CIDX-COD-CLI.
           READ CLI-IDX
               KEY IS CIDX-COD
           END-READ.
      *----
           IF FS-CLI NOT = 0
               IF FS-CLI = 23
                   DISPLAY ERR-23 FS-CLI
               ELSE
                   DISPLAY ERR-READ FS-CLI
                   PERFORM FIN THRU F-FIN
               END-IF
           ELSE
             PERFORM COPIAR THRU F-COPIAR
           END-IF.
       F-PORCODIGO. EXIT.

       COPIAR.
           IF (LS-TIPO-CLAVE EQUAL 'P')
             THEN MOVE CIDX-CUIT-CLI TO LS-CLI-CLAVE.
           MOVE CIDX-RAZON-SOCIAL TO LS-RAZON-SOCIAL.
           MOVE CIDX-DOMICILIO TO LS-DOMICILIO.
           MOVE CIDX-PORC-DESC TO LS-PORC-DESC.
       F-COPIAR. EXIT.

       ERROR-OPC-INV.
           DISPLAY 'ERROR! OPCION INVALIDA'.
       F-ERROR-OPC-INV. EXIT.

       FIN.
           GOBACK.
       F-FIN. EXIT.
      *---------------------------------------------------------------